package com.buyouchina.service.product.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.buyouchina.bean.privilege.Role;
import com.buyouchina.bean.privilege.User;
import com.buyouchina.bean.product.Outlets;
import com.buyouchina.service.base.DaoSupport;
import com.buyouchina.service.product.OutletsService;

@Service
public class OutletsServiceBean extends DaoSupport<Outlets> implements
		OutletsService {

	String hql;

	public List<Outlets> list(Integer managerid) {
		hql = "from Outlets o inner join fetch o.manager m where m.id=?1 ";
		return list(hql, managerid);
	}

	public Integer getRecordCount(Integer pid, Integer epid) {
		hql = "select count(o) from Outlets o where o.province.id between ?1 and ?2";
		return getCount(hql, pid, epid);
	}

	public List<Outlets> list(int firstResult, int maxResults, Integer pid,
			Integer epid) {
		hql = "select o from Outlets o inner join fetch o.province p "
				+ "where p.id between ?1 and ?2";
		return list(hql, firstResult, maxResults, pid, epid);
	}
	
	public List<Outlets> listByArea(Integer pid,Integer epid,User user){
		
		if(pid!=null){
			if(user.getRole().equals(Role.CLDSSM)){
				hql="from Outlets o where o.province.id between ?1 and ?2 and o.proxyManager.id=?3";
				return listByParams(hql,pid,epid,user.getId());
			}else{
				hql="from Outlets o where o.province.id between ?1 and ?2";
			}
			return listByParams(hql,pid,epid);
		}else{
			return getScrollData().getResultlist();
		}
	}
}
